﻿namespace SourceCodeRepository.Web.Views.ViewData
{
    using System;

    /// <summary>
    /// Contributor ViewData Class.
    /// </summary>
    public class ContributorViewData : IViewData, IEquatable<ContributorViewData>
    {
        /// <summary>
        /// Gets or sets the id of the domain object.
        /// </summary>
        /// <value>The id of the domain object.</value>
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>The name of the user.</value>
        public string UserName { get; set; }

        /// <summary>
        /// Gets or sets the email address.
        /// </summary>
        /// <value>The email address.</value>
        public string EmailAddress { get; set; }

        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
        /// </returns>
        public bool Equals(ContributorViewData other)
        {
            if (this == other)
            {
                return true;
            }

            if (this.Id == other.Id && this.EmailAddress == other.EmailAddress && this.Name == other.Name && this.UserName == other.UserName)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Serves as a hash function for a particular type.
        /// </summary>
        /// <returns>
        /// A hash code for the current <see cref="T:System.Object"/>.
        /// </returns>
        public override int GetHashCode()
        {
            return (this.Id.GetHashCode() + this.EmailAddress.GetHashCode() + this.Name.GetHashCode() +
                    this.UserName.GetHashCode()) % 11;
        }
    }
}
